const message = require("../models/message")

var express = require('express');
var router = express.Router();

const formidable = require('formidable');

//返回图片
router.post('/', (req, res, next) => {
    var form = new formidable.IncomingForm();
    form.parse(req, function (err, fields, files) {
        if (err) {
            res.json({ 'state': false })
        } else {
            // console.log(fields.UUID)
            message.find({
                UUID: fields.UUID,
                status: "unread"
            }, (err, docs) => {
                // console.log(docs)
                    if (err) {
                        res.json({ 'state': false, 'msg': err });
                    } else {
                        res.json({ 'state': true, 'result': docs.length });
                    }
                })
        }

    });

});

module.exports = router;